package com.itheima.edu.info.student.manager.dao;

import com.itheima.edu.info.student.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teas = new Teacher[5];
    public boolean addTeacher(Teacher tea) {
    // 使用标记位思想,先假设老师数组已满,无法添加对象数据
    int index = -1;
        for (int i = 0; i < teas.length; i++) {
            if(teas[i]==null){
                index = i;
                break;
            }
        }
        if(index == -1){
            return false;
        }else{
            teas[index] = tea;
            return true;
        }




    }
    //拿到数组容器的功能
    public Teacher[] findAllteacher() {
        return teas;
    }

    //修改功能
    public void updateTeacher(String updateId, Teacher tea) {
        int index = getIndex(updateId);
        teas[index] = tea;
    }


    //定义一个根据id获取元素索引值的方法
    public int getIndex(String id){
        int index = -1;
        for (int i = 0; i < teas.length; i++) {
            if(teas[i]!=null&&id.equals(teas[i].getId())){
                index = i;
                break;
            }
        }
        return index;
    }

    public void deleteTeacher(String id) {
        int  index = getIndex(id);
        teas[index] = null;
    }
}
